import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import Cookies from 'js-cookie'
const init_route = [
  {
    path: '/index',
    name: 'Index',
    component: () => import('@/views/index.vue'),
    meta: {
      title: '首页',
      is_show: true
    }
  },
  {
    path: '/task',
    name: 'task',
    component: () => import('@/views/home/task.vue'),
    meta: {
      title: '任务管理',
      is_show: true,
      keepAlive : true
    },
  },
  {
    path: '/detail',
    name: 'taskdetail',
    component: () => import('@/views/home/detail.vue'),
    meta: {
      title: '任务详情',
      is_show: false
    }
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/home/search.vue'),
    meta: {
      title: '搜索发布',
      is_show: true,
      keepAlive : true
    }
  },
  {
    path: '/information',
    name: 'Information',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/Information/index.vue'),
    meta: {
      title: '信息管理',
      path: '/information',
      is_show: true
    },
    children: [
      {
        path: 'manage',
        name: 'manage',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/Information/manage.vue'),
        meta: {
          title: '信息管理',
          is_show: true,
          keepAlive : true
        }
      },
      {
        path: 'payment',
        name: 'payment',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/Information/payment.vue'),
        meta: {
          title: '付款设置',
          is_show: true
        }
      }
    ]
  },
  {
    path: '/maintenance',
    name: 'maintenance',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/maintenance/index.vue'),
    meta: {
      title: '维护管理',
      path: '/maintenance',
      is_show: true
    },
    children: [
      {
        path: 'form',
        name: 'form',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/maintenance/form.vue'),
        meta: {
          title: '表单维护',
          is_show: true
        }
      },
      {
        path: 'category',
        name: 'category',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/maintenance/category.vue'),
        meta: {
          title: '标签维护',
          is_show: true
        }
      }
    ]
  },
  {
    path: '/users',
    name: 'users',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/users/index.vue'),
    meta: {
      title: '用户管理',
      path: '/user',
      is_show: true
    },
    children: [
      {
        path: 'list',
        name: 'list',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/users/list.vue'),
        meta: {
          title: '用户列表',
          is_show: true
        }
      },
      {
        path: 'application',
        name: 'application',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/users/application.vue'),
        meta: {
          title: '维护申请',
          is_show: true
        }
      },
      {
        path: ':id',
        name: 'detail',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/users/detail.vue'),
        meta: {
          title: '用户详情',
          is_show: false
        }
      }
    ]
  },
  {
    path: '/data',
    name: 'data',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/data/index.vue'),
    meta: {
      title: '数据统计',
      path: '/data',
      is_show: true
    },
    children: [
      {
        path: 'newusers',
        name: 'newusers',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/newusers.vue'),
        meta: {
          title: '新用户统计',
          is_show: true
        }
      },
      {
        path: 'user',
        name: 'user',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/user.vue'),
        meta: {
          title: '用户统计',
          is_show: true
        }
      },
      {
        path: 'orders',
        name: 'orders',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/orders.vue'),
        meta: {
          title: '订单统计',
          is_show: true
        }
      },
      {
        path: 'finance',
        name: 'finance',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/finance.vue'),
        meta: {
          title: '财务统计',
          is_show: true
        }
      },
      {
        path: 'outstanding',
        name: 'outstanding',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/outstanding.vue'),
        meta: {
          title: '维护人业绩统计',
          is_show: true
        }
      },
      {
        path: 'publisher',
        name: 'publisher',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/data/publisher.vue'),
        meta: {
          title: '发布人统计',
          is_show: true
        }
      }
    ]
  },
  {
    path: '/permissions',
    name: 'permissions',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/permissions/index.vue'),
    meta: {
      title: '权限管理',
      path: '/permissions',
      is_show: true
    },
    children: [
      {
        path: 'employee',
        name: 'employee',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/permissions/employee.vue'),
        meta: {
          title: '员工管理',
          is_show: true
        }
      },
      {
        path: 'department',
        name: 'department',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/permissions/department.vue'),
        meta: {
          title: '部门管理',
          is_show: true
        }
      }
    ]
  },
  {
    path: '/system',
    name: 'system',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/home/system/index.vue'),
    meta: {
      title: '系统配置',
      is_show: true
    },
    children: [
      {
        path: 'contribute',
        name: 'contribute',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/system/contribute.vue'),
        meta: {
          title: '贡献海报',
          is_show: true
        }
      },
      {
        path: 'drainage',
        name: 'drainage',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/system/drainage.vue'),
        meta: {
          title: '引流海报',
          is_show: true
        }
      },
      {
        path: 'sensitive',
        name: 'sensitive',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/home/system/sensitive.vue'),
        meta: {
          title: '敏感词管理',
          is_show: true
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/404.vue'),
        meta: {
          title: '敏感词管理',
          is_show: false
        }
      },
      {
        path: '/:pathMatch(.*)',
        redirect: '/404',
        meta: {
          title: '敏感词管理',
          is_show: false
        }
      }
    ]
  }
]
export const userInforStore = defineStore(
  'user_infor',
  () => {
    const user_data = ref()
    const access_token = ref(Cookies.get('access_token') || '')
    const menu = ref(init_route)
    return { user_data, access_token, menu }
  },
  {
    persist:  {
      key: 'user_infor',
      storage: localStorage
    }
  }
)
